Page({
    data: {
      username: '',
      password: '',
      resultText: '',
      logintData: []
    },

    onLoad(options) {
        //这是测试的数据
        var that = this
        wx.request({
            url: 'http://127.0.0.1:3000/Login',
            method: "get",
            success: function (res) {
                console.log(res.data)
                that.setData({logintData: res.data})
            }
        })
    },
    
    onUsernameInput(event) {
      this.setData({
        username: event.detail.value
      });
    },
    onPasswordInput(event) {
      this.setData({
        password: event.detail.value
      });
    },



   formSubmit(event) {
    const { username, password } = event.detail.value;
    if (!this.validateInput(username, password)) {
      this.setData({ resultText: '请输入用户名和密码' });
      return;
    }
    const foundUser = this.data.logintData.find(item => item.username === username && item.password === password);
    if (foundUser) {
      this.setData({ resultText: '登录成功' });
      // 跳转到主页面
      wx.switchTab({
        url: '/pages/Home/home',
        success: () => {
          console.log('跳转成功');
        },
        fail: (err) => {
          console.error('跳转失败：', err);
        }
      });
    } else {
      this.setData({ resultText: '账户名或密码错误' });
    }
  },
  validateInput(username, password) {
    return username && password;
  }















  });